package com.toy.service;

import com.toy.entity.goods.GoodsDTO;
import com.toy.mapper.goods.GoodsMapper;
import com.toy.query.goods.GoodsQuery;
import com.toy.utils.EasyUIResult;
import com.toy.utils.ListUtil;
import com.toy.utils.PageUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    private static final Log log = LogFactory.getLog(GoodsServiceImpl.class);
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public EasyUIResult queryGoods(GoodsQuery goodsQuery) {
        EasyUIResult easyUIResult = null;
        try {
            PageUtil.initPageHelper(goodsQuery);
            List<GoodsDTO> list = goodsMapper.queryGoods(goodsQuery);
            if (ListUtil.isRealList(list)) {
                easyUIResult = new EasyUIResult(PageUtil.getPageInfoTotal(list),list);
            }
        } catch (Exception e) {
           log.error(e.getMessage(),e);
        }
        return easyUIResult;
    }
}

